<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>上传提货单</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />

    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css" />
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css" />

    <link rel="stylesheet" href="/static/wx/css/reset.css" />
    <link rel="stylesheet" href="/static/wx/css/main.css" />
    <link rel="stylesheet" href="/static/wx/css/public_main.css" />
  </head>

  <body>
    <div class="page-group">
      <div class="page page-current" id="upload_sheet">
        <div class="content">
          <div class="red size-65 text-c upload-tip">
            提货单下载后签字盖章，需要上传
          </div>
          <div class="list-block media-list">
            <ul>
              {foreach($res as $k=>$v)}
              <li>
                <input type="hidden" value="{$v.policy_num}" id="policy_num">
                <input type="hidden" value="{$v.i_id}" id="i_id">
                <div class="item-content">
                  <div class="item-inner">
                    <div class="item-title-row">
                      <div class="item-title size-m">
                        报案号：<span>{$v.policy_num}</span>
                      </div>
                    </div>
                    <div class="item-subtitle size-m">
                        {$v.created_at}
                    </div>
                  </div>
                  <div class="upload-box">
                    {if($v.is_show == 2)}
                      <div class="upload">上传提货单<input class="uploader-input" type="file" accept="image/*" onchange="handleInputChange1(event)"/></div>
                    {/if}
                    {if($v.is_show == 1)}
                    <div class="upload-check">查看</div>
                    <div class="re-upload">重新上传<input class="uploader-input" type="file" accept="image/*" onchange="handleInputChange1(event)"/></div>
                    {/if}
                  </div>
                </div>
              </li>
            {/foreach}
            </ul>
          </div>
        </div>
      </div>
    </div>

    <script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/js/upload.js' charset='utf-8'></script>
    <script>
        function handleInputChange1(event) {
            var formData = handleInputChange(event);
            uploadImg(formData);

        }
        function  uploadImg(formData) {
            $.ajax({
                type: 'POST',
                url: "{:url('upload/index')}",
                data: formData,
                processData: false,
                contentType: false,
                cache: false,
                success: function (Json) {
                    console.log(Json.data)
                    if (Json.code == 200) {
                        var url = decodeURI(Json.data.url);
                        save(url);
                    } else {
                        $.alert('上传失败');
                    }
                }
            });
        }
        function save(url) {
            var i_id = $('#i_id').val();
            var policy_num = $('#policy_num').val();
            $.ajax({
                type: 'POST',
                url: "{:url('insurant/save_upload')}",
                data: {'policy_num':policy_num,'url':url,'type':3,'i_id':i_id},
                success: function (Json) {
                    if (Json.code == 200) {
                        $.alert('上传成功');
                        window.location.href='/wx/insurant/upload_bol';
                    } else {
                        $.alert('上传失败');
                    }
                }
            });


        }
    </script>



  </body>
</html>
